package com.mfw.springboot.model.vo;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.mfw.springboot.model.dto.trainingRule.TrainingRuleDto;
import com.mfw.springboot.model.entity.TrainingPlan;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 训练计划视图
 *
 * @author mfw
 * @from <a href="https://gitee.com/hanhuaifei/projects">我的gitee</a>
 * @Date 2024/9/26
 */
@Data
public class TrainingPlanVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 计划名称
     */
    private String planName;

    /**
     * 计划描述
     */
    private String description;

    /**
     * 开始时间
     */
    private Date startTime;

    /**
     * 结束时间
     */
    private Date endTime;

    /**
     * 制定教练ID
     */
    private Long userId;


    /**
     * 计划状态: active/inactive
     */
    private String status;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;


    private static final long serialVersionUID = 1L;


    /**
     * 关联规则ID与其状态列表（json 数组）
     */
    private List<TrainingRuleDto> ruleList;


    /**
     * 创建用户信息
     */
    private UserVO user;

    /**
     * 封装类转对象
     *
     * @param trainingPlanVO
     * @return
     */
    public static TrainingPlan voToObj(TrainingPlanVO trainingPlanVO) {
        if (trainingPlanVO == null) {
            return null;
        }
        TrainingPlan trainingPlan = new TrainingPlan();
        BeanUtils.copyProperties(trainingPlanVO, trainingPlan);
        List<TrainingRuleDto> ruleList = trainingPlanVO.getRuleList();
        trainingPlan.setRules(JSONUtil.toJsonStr(ruleList));
        return trainingPlan;
    }

    /**
     * 对象转封装类
     *
     * @param trainingPlan
     * @return
     */
    public static TrainingPlanVO objToVo(TrainingPlan trainingPlan) {
        if (trainingPlan == null) {
            return null;
        }
        TrainingPlanVO trainingPlanVO = new TrainingPlanVO();
        BeanUtils.copyProperties(trainingPlan, trainingPlanVO);
        trainingPlanVO.setRuleList(JSONUtil.toList(trainingPlan.getRules(), TrainingRuleDto.class));
        return trainingPlanVO;
    }
}
